package com.qlk.odcinterface.manager.impl;

import java.util.List;

import com.qlk.common.manager.BaseManager;
import com.qlk.common.utils.page.PageUtil;
import com.qlk.odcinterface.domain.PmsProductPromotionItem;
import com.qlk.odcinterface.domain.query.PmsProductPromotionItemQuery;
import com.qlk.odcinterface.dao.PmsProductPromotionItemDao;
import com.qlk.odcinterface.manager.PmsProductPromotionItemManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * PmsProductPromotionItemManager接口的实现类
 * 
 * @author zhaoyanan
 * @version 2016-4-14 13:22:58
 * 
 */
@Component
public class PmsProductPromotionItemManagerImpl extends BaseManager implements PmsProductPromotionItemManager {
	
    @Autowired
    private PmsProductPromotionItemDao pmsProductPromotionItemDao;

    /**
     * {@inheritDoc}
     */
    public boolean insert(final List<PmsProductPromotionItem> pmsProductPromotionItemList) {
        boolean resultFlag = false;
        if (null != pmsProductPromotionItemList && pmsProductPromotionItemList.size() > 0) {
            for (PmsProductPromotionItem pmsProductPromotionItem : pmsProductPromotionItemList) {
                resultFlag = pmsProductPromotionItemDao.insert(pmsProductPromotionItem);
                if (!resultFlag) {
                    throw new RuntimeException("批量新增表信息异常");
                }
            }
        }

        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    public boolean insert(PmsProductPromotionItem pmsProductPromotionItem) {
        return pmsProductPromotionItemDao.insert(pmsProductPromotionItem);
    }

    /**
     * {@inheritDoc}
     */
    public boolean update(final PmsProductPromotionItem pmsProductPromotionItem) {
        return pmsProductPromotionItemDao.update(pmsProductPromotionItem);
    }

    /**
     * {@inheritDoc}
     */
    public List<PmsProductPromotionItem> queryPmsProductPromotionItemList(PmsProductPromotionItemQuery queryBean) {
        return pmsProductPromotionItemDao.queryPmsProductPromotionItemList(queryBean);
    }

    /**
     * {@inheritDoc}
     */
    public List<PmsProductPromotionItem> queryPmsProductPromotionItemListWithPage(PmsProductPromotionItemQuery queryBean,
            PageUtil pageUtil) {
        if (null == queryBean) {
            queryBean = new PmsProductPromotionItemQuery();
        }

        // 查询总数
        int totalItem = queryPmsProductPromotionItemCount(queryBean);

        if (pageUtil == null) {
            pageUtil = new PageUtil();
        }
        pageUtil.setTotalRow(totalItem);
        pageUtil.init();
        
        if (totalItem > 0) {
            queryBean.setPageIndex(pageUtil.getCurPage());
            queryBean.setPageSize(pageUtil.getPageSize());
            // 调用Dao翻页方法
            return pmsProductPromotionItemDao.queryPmsProductPromotionItemListWithPage(queryBean);
        }
        return null;
    }

    /**
     * {@inheritDoc}
     */
    public int queryPmsProductPromotionItemCount(PmsProductPromotionItemQuery queryBean) {
        return pmsProductPromotionItemDao.queryPmsProductPromotionItemCount(queryBean);
    }

    /**
     * {@inheritDoc}
     */
    public boolean delete(PmsProductPromotionItem pmsProductPromotionItem) {
        return pmsProductPromotionItemDao.delete(pmsProductPromotionItem);
    }
    public boolean deletePmsProductPromotionItem(PmsProductPromotionItem pmsProductPromotionItem) {
        return pmsProductPromotionItemDao.deletePmsProductPromotionItem(pmsProductPromotionItem);
    }
    /**
     * {@inheritDoc}
     */
    public PmsProductPromotionItem getPmsProductPromotionItemById(Long id) {
        return pmsProductPromotionItemDao.getPmsProductPromotionItemById(id);
    }

    /**
     * {@inheritDoc}
     */
    public boolean delete(final PmsProductPromotionItem[] pmsProductPromotionItems) {
        boolean resultFlag = false;
        if (null != pmsProductPromotionItems && pmsProductPromotionItems.length > 0) {
            for (int i = 0; i < pmsProductPromotionItems.length; i++) {
                resultFlag = delete(pmsProductPromotionItems[i]);
                if (!resultFlag) {
                    throw new RuntimeException("批量删除表信息异常!");
                }
            }
        }

        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    public boolean exist(PmsProductPromotionItem pmsProductPromotionItem) {
        return pmsProductPromotionItemDao.exist(pmsProductPromotionItem);
    }
}
